package org.halk.myutils;

import org.apache.commons.io.FileUtils;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

/**
 * 读取文件夹下的sql文件，替换库名
 *
 * @author halk
 * @date 2025/7/22 14:14
 **/
public class ReadFileReplaceString {


    /**
     * 读取文件夹下的sql文件，替换库名
     * @throws IOException
     */
    @Test
    public void readFile() throws IOException {
        String folder = "E:\\sql\\test2";
        Collection<File> files = FileUtils.listFiles(new File(folder), new String[]{"sql"}, false);

        for (File file : files) {
            String content = null;
            content = FileUtils.readFileToString(file, "utf-8");
            if (!content.contains("biims_console.")) {
                continue;
            }
            System.out.println(file.getName());
//            content = content.replaceAll("biims_console.", "biims_clctdash.");
            content = content.replaceAll("biims_console.", "");
            FileUtils.writeStringToFile(file, content, "utf-8");
        }

    }
}
